package com.haiyuancloud.common.redis.listener;

import com.haiyuancloud.common.core.utils.SpringUtils;
import com.haiyuancloud.common.redis.service.CaffeineCacheService;
import com.haiyuancloud.rest.service.ClearLocalCacheService;
import com.haiyuancloud.rest.service.impl.ClearLocalCacheServiceImpl;
import com.haiyuancloud.util.ObjectUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import java.util.List;

/***
 * 缓存消息监听器
 */
public class RedisCacheMessageListener implements MessageListener {

    /***
     * 日志打印
     */
    private static Logger logger = LoggerFactory.getLogger(RedisCacheMessageListener.class);

    @Override
    public void onMessage(Message message, byte[] bytes) {
        try {
            ClearLocalCacheService clearLocalCacheService = SpringUtils.getBean(ClearLocalCacheServiceImpl.BEAN_ID);
            String tmp = message.toString();
            clearLocalCacheService.clearLocalCache(tmp);
        }catch (Exception e){
            logger.error("异常#"+e.getMessage(), e);
        }
    }
}
